package com.kunpeng.weibo.tencent.api;

import java.util.ArrayList;
import java.util.List;

import com.kunpeng.weibo.tencent.beans.OAuth;
import com.kunpeng.weibo.tencent.beans.QParameter;
import com.kunpeng.weibo.tencent.utils.OAuthClient;
import com.kunpeng.weibo.tencent.utils.QHttpClient;

public class T_API extends Request_API {

	public T_API(OAuth oauth) {
		super(oauth);
	}

	public String add(String content, float jing, float wei) {
		if (mOAuth == null) {
			throw new NullPointerException();
		}
		String url = "http://open.t.qq.com/api/t/add";
		try {
			List<QParameter> parameters = new ArrayList<QParameter>();
			parameters.add(new QParameter("format", "json"));
			parameters.add(new QParameter("content", content));
			parameters.add(new QParameter("clientip", ""));
			parameters.add(new QParameter("jing", String.valueOf(jing)));
			parameters.add(new QParameter("wei", String.valueOf(wei)));
			parameters.addAll(mOAuth.getTokenParams());
			OAuthClient oac = new OAuthClient();
			String queryString = oac.getOauthParams(url, "POST", mOAuth.getOauth_consumer_secret(), mOAuth.getOauth_token_secret(), parameters);
			return new QHttpClient().httpPost(url, queryString);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public String t_add_pic(String content, String picPath, float jing, float wei) {
		if (mOAuth == null) {
			throw new NullPointerException();
		}
		String url = "http://open.t.qq.com/api/t/add_pic";
		try {
			List<QParameter> parameters = new ArrayList<QParameter>();
			parameters.add(new QParameter("format", "json"));
			parameters.add(new QParameter("content", content));
			parameters.add(new QParameter("clientip", ""));
			parameters.add(new QParameter("jing", String.valueOf(jing)));
			parameters.add(new QParameter("wei", String.valueOf(wei)));
			parameters.addAll(mOAuth.getTokenParams());
			OAuthClient oac = new OAuthClient();
			String queryString = oac.getOauthParams(url, "POST", mOAuth.getOauth_consumer_secret(), mOAuth.getOauth_token_secret(), parameters);
			return new QHttpClient().httpPostWithFile(url, queryString, picPath);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public String add_pic_url(String content, String picUrl, float jing, float wei) {
		if (mOAuth == null) {
			throw new NullPointerException();
		}
		String url = "http://open.t.qq.com/api/t/add_pic_url";
		try {
			List<QParameter> parameters = new ArrayList<QParameter>();
			parameters.add(new QParameter("format", "json"));
			parameters.add(new QParameter("content", content));
			parameters.add(new QParameter("clientip", ""));
			parameters.add(new QParameter("jing", String.valueOf(jing)));
			parameters.add(new QParameter("wei", String.valueOf(wei)));
			parameters.add(new QParameter("pic_url", picUrl));
			parameters.addAll(mOAuth.getTokenParams());
			OAuthClient oac = new OAuthClient();
			String queryString = oac.getOauthParams(url, "POST", mOAuth.getOauth_consumer_secret(), mOAuth.getOauth_token_secret(), parameters);
			return new QHttpClient().httpPost(url, queryString);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
